package com.tencent.ied.bk.handler.impl;

import com.tencent.ied.bk.entity.SearchAbstractInfo;
import com.tencent.ied.bk.handler.Handler;
import com.tencent.ied.bk.handler.HandlerObject;
import lombok.extern.slf4j.Slf4j;

import java.util.List;
import java.util.stream.Collectors;

/**
 * 对待搜索的数据进行过滤
 *
 * @author chen_yu
 * @date 2021/3/11 5:15
 */
@Slf4j
public class FirstContainsHandler implements Handler {

    /**
     * 过滤出包含此对象的列表
     *
     * @param handlerObject 处理对象
     */
    @Override
    public void handle(HandlerObject handlerObject) {
        List<SearchAbstractInfo> collect = handlerObject.getSearchAbstractInfoList().stream()
                .filter(abstractInfo -> abstractInfo.getContent().toLowerCase().contains(handlerObject.getStrKeyWord()))
                .peek(abstractInfo -> abstractInfo.getSearchCount().incrementAndGet())
                .collect(Collectors.toList());
        handlerObject.setSearchAbstractInfoList(collect);
    }
}
